package com.lagou;

import com.lagou.bean.ComsumerComponet;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.*;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class AnnotationConsumerMain  {


    public static void main(String[] args) throws  Exception {
        System.out.println("-------------");
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        // 获取消费者组件
        ComsumerComponet service = context.getBean(ComsumerComponet.class);

        ExecutorService pool = Executors.newFixedThreadPool(8);
        long start = System.currentTimeMillis();

        for (int i = 0; i < 2000; i++) {
            pool.submit(() ->{
                    service.sayHello("world1");
            });
            pool.submit(() ->{
                service.sayHello2("world2");
            });
            pool.submit(() ->{
                service.sayHello3("world3");
            });
            if (i%2000==0){
                System.out.println("开始"+start+", 耗时："+ (System.currentTimeMillis()-start));
            }
        }





    }
    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "com.lagou.bean")
    @EnableDubbo
    static  class  ConsumerConfiguration{
        @Bean
        public RegistryConfig registryConfig(){
            RegistryConfig  registryConfig  = new RegistryConfig();
            registryConfig.setAddress("zookeeper://192.168.172.130:2181?timeout=10000");
            //registryConfig.setTimeout(10000);
            return   registryConfig;
        }
    }
}
